package com.guigu.serviceoss.component;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.CommonResponse;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 消息的消费者取出验证码输出
 */
@Component
public class SmsMessageConsumer {

    @Autowired
    private SmsUtlis smsUtlis;

    @RabbitListener(queues = "queue.sms")
    public void onMessage(Message message) {
        String jsonString = new String(message.getBody());
        Map<String, String> map = JSON.parseObject(jsonString, Map.class);
        String phone = map.get("phone");
        String code = map.get("code");
        Map<String,Object> param = new HashMap<>();
        param.put("code",code);
        CommonResponse response = smsUtlis.send(param, phone);
        System.out.println(response);
        System.out.println("手机号：" + phone + ",验证码：" + code);
    }
}
